package com.xuan.webfinally.mapper;

import com.xuan.webfinally.entity.SlopeSoilData;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuan.webfinally.entity.pax5;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 土壤温度和水分占比监测数据表 Mapper 接口
 * </p>
 *
 * @author gyuxuan
 * @since 2025-09-08
 */
public interface SlopeSoilDataMapper extends BaseMapper<SlopeSoilData> {

    @Select("SELECT device_sn,monitor_id, soil_temperature0, soil_moisture_ratio0, " +
            "soil_temperature1, soil_temperature2, soil_temperature3, " +
            "soil_temperature4, soil_moisture_ratio1, soil_moisture_ratio2, " +
            "soil_moisture_ratio3, soil_moisture_ratio4, create_time, update_time " +
            "FROM (" +
            "    SELECT *, " +
            "    ROW_NUMBER() OVER (PARTITION BY device_sn ORDER BY create_time DESC) AS rn " +
            "    FROM slope_soil_data " +
            "    WHERE slope_id = #{deptId} " +
            ") t " +
            "WHERE rn = 1")
    List<pax5> selectSoilDataList(String deptId);
}
